var t = getApp();

Page({
    data: {
        Interval: null,
        showPacket: !1,
        name: "",
        is_cps: "",
        order_id: "",
        order_id_new: '',
    },
    onLoad: function(t) {
      console.log(t,'tttttttttt')
        wx.setNavigationBarTitle({
            title: "跳转中"
        }), console.log(t), t.is_cps && this.setData({
            is_cps: t.is_cps
        }), t.name && this.setData({
            name: t.name
        }), t.ids && this.setData({
            order_id: t.ids
        }), t.sn && this.setData({
            order_sn: t.sn
        }),  t.order_id_new && this.setData({
          order_id_new: t.order_id_new
      }), this.getData();
        // wx.enableAlertBeforeUnload({
        //   message: '订单支付中，请勿离开页面',
        //   success(res) {
        //     console.log('success:', res)
        //   },
        //   fail(res) {
        //     console.log('fail:', res)
        //   },
        //   complete(res) {
        //     console.log('complete:', res)
        //   }
        // })
    },
    toPacket: function() {
        wx.navigateTo({
            url: "/packageE/ConsumePacket/ConsumePacketSuccess/ConsumePacketSuccess?order_id=" + this.data.order_id.toString()
        });
    },
    onClickHide: function() {
        this.setData({
            showPacket: !1
        }), this.toRedirect(this.data.redirect);
    },
    getData: function() {
      console.log(';;;;;;;;;;;')
        var e = this, a = {}, r = "";
        "tourAround" == this.data.name ? (r = "plugin.travel-around.frontend.payment.payment.checkOrderPay", 
        a = {
            order_id: this.data.order_id
        }) : (r = "order.merge-pay.check-order-pay", a = {
            order_pay_id: this.data.order_id
        });
        var n = t.getNetAddresss(r);
        t._postNetWork({
            url: n,
            data: a,
            success: function(a) {
              console.log(a,'order.merge-pay.check-order-pay')
              // return
              t._postNetWork({
                url: t.getNetAddresss("HuanNiu.web_pay_last"),
                data: {
                    order_id: e.data.order_id_new,
                    uid: wx.getStorageSync("uid")?wx.getStorageSync("uid"):wx.getStorageSync("yz_uid")
                },
                success: function(t) {
                  console.log(t,'jsjsjsjsjsjsjskldkldldld')
                   if(1 == t.data.result) {
                     console.log('成功过了飒飒飒')
                    // a.toRedirect(e)
                   }
                },
                fail: function(t) {
                    // a.toRedirect(e);
                }
            });
                var r = a.data;
                1 == r.result ? 1 == r.data.status ? (e.setData({
                    redirect: r.data.redirect
                }), e.checkoutConsumePacket(r.data.redirect), clearInterval(e.data.Interval), e.data.Interval = null) : e.data.Interval || (e.data.Interval = setInterval(function() {
                    e.getData();
                }, 1e3)) : t.tips(r.msg);
            },
            fail: function(t) {}
        });
    },
    checkoutConsumePacket: function(e) {
      console.log('checkoutConsumePacket',e)
        var a = this, r = wx.getStorageSync("yz_basic_info");
        if (r && 1 == r.globalParameter.consume_red_packet_status) {
          console.log('走了11111111')
            var n = t.getNetAddresss("plugin.consume-red-packet.Frontend.Modules.Packet.Controllers.has.index");
            t._postNetWork({
                url: n,
                data: {
                    order_id: this.data.order_id.split(",")
                },
                success: function(t) {
                    1 == t.data.result ? a.setData({
                        showPacket: !0
                    }) : a.toRedirect(e);
                },
                fail: function(t) {
                    a.toRedirect(e);
                }
            });
        } else {
          console.log('走了22222222',this.data.order_id_new)
        //   t._postNetWork({
        //     url: t.getNetAddresss("HuanNiu.web_pay_last"),
        //     data: {
        //         order_id: this.data.order_id_new,
        //         uid: wx.getStorageSync("uid")
        //     },
        //     success: function(t) {
        //       console.log(t,'jsjsjsjsjsjsjskldkldldld')
        //        if(1 == t.data.result) {
        //          console.log('成功过了飒飒飒')
        //         a.toRedirect(e)
        //        }
        //     },
        //     fail: function(t) {
        //         a.toRedirect(e);
        //     }
        // });
          this.toRedirect(e);
        }
    },
    toRedirect: function(t) {
        console.log(t), this.data.is_cps ? wx.navigateTo({
            url: "/packageA/member/order/cpsCoupon/cpsCoupon"
        }) : "Myshaky" != this.data.name ? this.data.order_sn && this.payCallBack(t) : wx.navigateTo({
            url: "/packageC/Myshaky/activityHome/activityHome"
        });
    },
    payCallBack: function(e) {
        console.log(e);
        var a = "";
        if (1 != t.globalData.store_alone_temp) if (t._isTextEmpty(e)) wx.reLaunch({
            url: "/packageG/index/index"
        }); else try {
            if ("groups" != this.data.name && "ywmGroup" != this.data.name || -1 == e.indexOf("group_detail")) wx.redirectTo({
                url: e,
                fail: function(t) {
                    console.log(t), wx.reLaunch({
                        url: "/packageG/index/index"
                    });
                }
            }); else {
                var r = e.match(/group_detail\/(\S*)\?i/)[1];
                a = "/packageB/member/group/GroupDetail/GroupDetail?id=" + (r = r.split("/"))[0], 
                "ywmGroup" == this.data.name && (a += "&plu=ywm"), r[1] ? wx.redirectTo({
                    url: a + "&store_id=" + r[1]
                }) : wx.redirectTo({
                    url: a
                });
            }
        } catch (t) {
            wx.reLaunch({
                url: "/packageG/index/index"
            });
        } else wx.reLaunch({
            url: "/packageG/independent_store/index/index?store_id=" + t.globalData.STORE_ID
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {
        clearInterval(this.data.Interval), this.data.Interval = null;
    },
    onUnload: function() {
        clearInterval(this.data.Interval), this.data.Interval = null;
    },
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});